package com.example.sqliterecyclerview;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class AddActivity extends AppCompatActivity {
    private MySQLiteOpenHelper helper;
    private EditText edtNo,edtName,edtAge;
    private Button btnSave;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add);
        helper = new MySQLiteOpenHelper(AddActivity.this,"stu.db",null,1);

        edtNo = findViewById(R.id.edt_no);
        edtName = findViewById(R.id.edt_name);
        edtAge = findViewById(R.id.edt_age);
        btnSave = findViewById(R.id.btn_save);

        btnSave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String stuno = edtNo.getText().toString();
                String name = edtName.getText().toString();
                int age = Integer.parseInt(edtAge.getText().toString());

                SQLiteDatabase writableDatabase = helper.getWritableDatabase();
                ContentValues values = new ContentValues();
                values.put("stuno",stuno);
                values.put("name",name);
                values.put("age",age);
                writableDatabase.insert("student",null,values);

                finish();
            }
        });
    }
}